#!/bin/sh
#
MARCIMPORT=/usr/local/marcimport
SABRE=/usr/local/vufind-smu
# Disable JETTY_CONSOLE output -- it causes problems when run by cron:
export JETTY_CONSOLE=/dev/null
#
date
#
############################################
# Get files...
cd $MARCIMPORT
pwd
cd partial
cd sussexincoming
rm *

# sussexincoming is now empty.
echo "Sussex daily import starting"
sleep 1
date
for FILENAME in $(ssh talis@ustalis 'ls -t /scratch/primo/export_delta |head -2')
do
	echo processing $FILENAME
	scp talis@ustalis.lib.sussex.ac.uk:/scratch/primo/export_delta/$FILENAME .
	echo copied. now extracting $FILENAME
	tar xvzf $FILENAME 
	sleep 1
done

echo file copying and extracting finished 
date

for MARCFILE in $(ls *.mrc)
do
	cd $MARCIMPORT/partial/sussexincoming
	echo marc merge $MARCFILE
	$SABRE/marc_merge_vufind.pl $MARCFILE ../sussexprocessed/$MARCFILE susx
	echo importing $MARCFILE
	cd $SABRE
	./import-marc.sh $MARCIMPORT/partial/sussexprocessed/$MARCFILE
	echo import of $MARCIMPORT complete 
	date
	sleep 1
done



# $SABRE/marc_merge_vufind.pl sussexincoming/grabbed.bibsg5.mrc sussexprocessed/sussex5.mrc susx
#./import-marc.sh $MARCIMPORT/partial/sussexprocessed/sussex5.mrc

echo daily sussex import process complete
date
cd $SABRE 
cd util
php optimize.php
